home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / archie-1.4.1 / vlalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-18  |  2.2 KB  |  108 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. #include <pfs.h>
  11. #include <pmachine.h>
  12.  
  13. static VLINK    lfree = NULL;
  14. int        vlink_count = 0;
  15. int        vlink_max = 0;
  16.  
  17. /*
  18.  * vlalloc - allocate and initialize vlink structure
  19.  *
  20.  *    VLALLOC returns a pointer to an initialized structure of type
  21.  *    VLINK.  If it is unable to allocate such a structure, it
  22.  *    returns NULL.
  23.  */
  24. VLINK
  25. vlalloc()
  26.     {
  27.     VLINK    vl;
  28.     if(lfree) {
  29.         vl = lfree;
  30.         lfree = lfree->next;
  31.     }
  32.     else {
  33.         vl = (VLINK) malloc(sizeof(VLINK_ST));
  34.         if (!vl) return(NULL);
  35.         vlink_max++;
  36.     }
  37.  
  38.     vlink_count++;
  39.  
  40.     /* Initialize and fill in default values */
  41.     /* Since all but four are set to a zero-value,
  42.        why not just wipe it clean?  */
  43.     ZERO(vl);
  44.  
  45.     vl->linktype = 'L';
  46.     vl->type = stcopy("FILE");
  47.     vl->hosttype = stcopy("INTERNET-D");
  48.     vl->nametype = stcopy("ASCII");
  49.  
  50.     return(vl);
  51.     }
  52.  
  53. /*
  54.  * vlfree - free a VLINK structure
  55.  *
  56.  *    VLFREE takes a pointer to a VLINK structure and adds it to
  57.  *    the free list for later reuse.
  58.  */
  59. void
  60. vlfree(vl)
  61.     VLINK    vl;
  62.     {
  63.         extern int string_count;
  64.  
  65.     if(vl->dontfree) return;
  66.     /* many of these don't need to call stfree(); since a check
  67.        for pointer validity's already done before even calling
  68.        it, we can just call free() here then do one big decrement
  69.        of string_count at the end.  */
  70.     if(vl->name) free(vl->name);
  71.     stfree(vl->type);
  72.     if(vl->replicas) vllfree(vl->replicas);
  73.     stfree(vl->hosttype);
  74.     if(vl->host) free(vl->host);
  75.     stfree(vl->nametype);
  76.     if(vl->filename) free(vl->filename);
  77.     if(vl->args) free(vl->args);
  78.     if(vl->lattrib) atlfree(vl->lattrib);
  79.     /* No allocation routines for f_info yet */
  80.     vl->f_info = NULL;
  81.     vl->next = lfree;
  82.     vl->previous = NULL;
  83.     lfree = vl;
  84.     vlink_count--;
  85.     string_count -= 4; /* freed name, host, filename, and args */
  86.     }
  87.  
  88. /*
  89.  * vllfree - free a VLINK structure
  90.  *
  91.  *    VLLFREE takes a pointer to a VLINK structure frees it and any linked
  92.  *    VLINK structures.  It is used to free an entrie list of VLINK
  93.  *    structures.
  94.  */
  95. void
  96. vllfree(vl)
  97.     VLINK    vl;
  98.     {
  99.     VLINK    nxt;
  100.  
  101.     while((vl != NULL) && !vl->dontfree) {
  102.         nxt = vl->next;
  103.         vlfree(vl);
  104.         vl = nxt;
  105.     }
  106.     }
  107.  
  108.